package com.yang.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.yang.demo.common.Result;
import com.yang.demo.entity.User;
import com.yang.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private UserService userService;

    @GetMapping
    public String hello() {
        return "hello me";
    }

    @GetMapping("/list")
    public List<User> list(){
        return userService.list();
    }

    @PostMapping("/listP")
    public Result listP(@RequestBody User user){
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(user.getUsername())){
            lambdaQueryWrapper.like(User::getUsername,user.getUsername());
        }
        return Result.suc(userService.list(lambdaQueryWrapper));
    }

}
